package com.tuni.birthdaymoney.service.util.email;

import java.text.SimpleDateFormat;

import com.tuni.birthdaymoney.persistence.entity.Person;

public class TemplateUtils {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM");

    public static String format(String template, Person birthdayMan, Person receiver) {
        String result = template;
        result = result.replace("%bm_firstname%", birthdayMan.getFirstName());        
        result = result.replace("%bm_firstmiddlename%", birthdayMan.createFirstMiddleName());
        result = result.replace("%bm_fullname%", birthdayMan.createFullName());
        result = result.replace("%bm_date%", dateFormat.format(birthdayMan.getBirthday().toGregorianCalendar().getTime()));
        result = result.replace("%rc_firstname%", receiver.getFirstName());
        result = result.replace("%rc_firstmiddlename%", receiver.createFirstMiddleName());
        result = result.replace("%rc_fullname%", receiver.createFullName());
        result = result.replace("%rc_token%", receiver.getAuthToken());
        return result;
    }
}
